// Copyright 2024 Tvux
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package _012

// intToRoman
// 因为已经确定了num的范围是 1 <= num <= 3999
// 所以可以先划分num的各个位，千分位、百分位、十位、个位
// 然后拼接每位数字对应的罗马数字即可
func intToRoman(num int) string {
	r := [4][10]string{
		{
			"", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX", // 0 - 9
		},
		{
			"", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC",
			// 0 10 20 30 40 50 60 70 80 90
		},
		{
			"", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM",
			// 0 100 200 300 400 500 600 700 800 900
		},
		{
			"", "M", "MM", "MMM",
			// 0 1000 2000 3000
		},
	}

	return r[3][num/1000] + r[2][num/100%10] + r[1][num/10%10] + r[0][num%10]
}
